import java.util.*;

public class Mult9x9 {
    static public void for9x9() {
        System.out.printf("for:\n");
        for (int i = 1; i < 10; ++i) {
            for (int j = 1; j <= i; ++j) {
                if (i % 2 == 0) {
                    System.out.printf("%d x %d = %2d ", j, i, i * j);
                } else {
                    System.out.printf("\033[31m%d x %d = %2d\033[0m ",
                                        j, i, i * j);
                }
            }
            System.out.println();
        }
        System.out.println();
    }

    static public void while9x9() {
        int i, j;
        System.out.printf("while:\n");
        i = 1;
        while (i < 10) {
            j = 1;
            while (j <= i) {
                if (j % 2 == 0) {
                    System.out.printf("%d x %d = %2d ", j, i, i * j);
                } else {
                    System.out.printf("\033[32m%d x %d = %2d\033[0m ",
                                        j, i, i * j);
                }
                j++;
            }
            System.out.println();
            i++;
        }
        System.out.println();
    }

    public static void dowhile9x9() {
        int i, j;
        System.out.printf("do...while:\n");
        i = 1;
        do {
            j = 1;
            do {
                if (j % 2 == 0) {
                    System.out.printf("%d x %d = %2d ", j, i, i * j);
                } else {
                    System.out.printf("\033[33m%d x %d = %2d\033[0m ",
                                        j, i, i * j);
                }
                j++;
            } while (j <= i);
            System.out.println();
            i++;
        } while (i < 10);
        System.out.println();
    }

    static public void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int input;
        boolean quit = false;

        while (!quit) {
            System.out.printf("1. 使用for打印九九乘法表\n"
                              + "2. 使用while打印九九乘法表\n"
                              + "3. 使用do..while打印九九乘法表\n"
                              + "4. 退出\n"
                              + "请输入[1 - 4]: ");
            input = sc.nextInt();

            switch (input) {
                case 1:
                    for9x9();
                    break;
                case 2:
                    while9x9();
                    break;
                case 3:
                    dowhile9x9();
                    break;
                case 4:
                    quit = true;
                    break;
                default:
                    System.out.printf("你想干吗?\n");
                    break;
            }

/*
 *             if (input == 4) {
 *                 break;
 *             } else if (input == 1) {
 *                 System.out.printf("for:\n");
 *                 for (i = 1; i < 10; ++i) {
 *                     for (j = 1; j <= i; ++j) {
 *                         if (i % 2 == 0) {
 *                             System.out.printf("%d x %d = %2d ", j, i, i * j);
 *                         } else {
 *                             System.out.printf("\033[31m%d x %d = %2d\033[0m ", j, i, i * j);
 *                         }
 *
 *                     }
 *                     System.out.println();
 *                 }
 *                 System.out.println();
 *             } else if (input == 2) {
 *                 System.out.printf("while:\n");
 *                 i = 1;
 *                 while (i < 10) {
 *                     j = 1;
 *                     while (j <= i) {
 *                         if (j % 2 == 0) {
 *                             System.out.printf("%d x %d = %2d ", j, i, i * j);
 *                         } else {
 *                             System.out.printf("\033[32m%d x %d = %2d\033[0m ", j, i, i * j);
 *                         }
 *                         j++;
 *                     }
 *                     System.out.println();
 *                     i++;
 *                 }
 *                 System.out.println();
 *             } else if (input == 3) {
 *                 System.out.printf("do...while:\n");
 *                 i = 1;
 *                 do {
 *                     j = 1;
 *                     do {
 *                         if (j % 2 == 0) {
 *                             System.out.printf("%d x %d = %2d ", j, i, i * j);
 *                         } else {
 *                             System.out.printf("\033[33m%d x %d = %2d\033[0m ", j, i, i * j);
 *                         }
 *                         j++;
 *                     } while (j <= i);
 *                     System.out.println();
 *                     i++;
 *                 } while (i < 10);
 *                 System.out.println();
 *             }
 */
        }

    }
}
